home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Various / DevDisk 65 (1989)(DevWare PD).zip / DevDisk 65 (1989)(DevWare PD).adf / ifflib / Examples / AnimExample.c < prev    next >
C/C++ Source or Header  |  1990-07-11  |  4KB  |  129 lines

  1. /*
  2.     AnimExample.c - A simple DPaint animation player by Christian A. Weber.
  3.     This program is in the public domain, use at your own risk.
  4.     Requires the iff.library in the LIBS: dircetory. Compiles with
  5.     Lattice C V5.04 (LC -L AnimExample), should also work with Manx.
  6. */
  7.  
  8. #include <exec/types.h>
  9. #include <graphics/gfxbase.h>
  10. #include <intuition/intuition.h>
  11. #include <libraries/iff.h>            /* Our iff header file */
  12.  
  13. struct Library *IntuitionBase,*IFFBase, *OpenLibrary();
  14. struct GfxBase *GfxBase;
  15.  
  16. struct NewScreen ns =
  17. {
  18.     0,0,0,0,0,0,0, NULL, CUSTOMSCREEN|SCREENBEHIND|SCREENQUIET, NULL,
  19.     (STRPTR)"Anim Player Example by Christian A. Weber", NULL, NULL
  20. };
  21.  
  22. struct Screen *screen1,*screen2, *OpenScreen();
  23. ULONG *ifffile;
  24.  
  25. void SetOverscan(screen)        /* Adjust the screen position for overscan */
  26. register struct Screen *screen;
  27. {
  28.     register WORD rows = GfxBase->NormalDisplayRows;
  29.     register WORD x=screen->Width,y=screen->Height;
  30.     register struct ViewPort *vp=&(screen->ViewPort);
  31.  
  32.     if(rows>300) rows>>=1;
  33.     x -= 320;  if(vp->Modes & HIRES) x -= 320;
  34.     y -= rows; if(vp->Modes & LACE)  y -= rows;
  35.     x >>=1; if(x<0) x=0; y >>=1; if(y<0) y=0; if(y>40) y=40;
  36.     if(vp->Modes & HAM)    /* Correct overscan HAM color distortions */
  37.     {
  38.         if(GfxBase->ActiView->DxOffset-x < 96)
  39.             x=GfxBase->ActiView->DxOffset-96;
  40.     }
  41.     vp->DxOffset = -x; vp->DyOffset = -y;
  42.     RemakeDisplay();
  43. }
  44.  
  45. void Fail(text)
  46. char *text;
  47. {
  48.     printf("%s, IFFError = %ld\n",text,IFFError());
  49.  
  50.     if(ifffile) CloseIFF(ifffile);
  51.     if(screen1) CloseScreen(screen1);
  52.     if(screen2) CloseScreen(screen2);
  53.  
  54.     if(IFFBase) CloseLibrary(IFFBase);    /* MUST ALWAYS BE CLOSED !! */
  55.     CloseLibrary(IntuitionBase);
  56.     CloseLibrary(GfxBase);
  57.     exit(0);
  58. }
  59.  
  60. void main(argc,argv)
  61. int argc;
  62. char **argv;
  63. {
  64.     register LONG count,i,delay;
  65.     register ULONG *form,*loopform;
  66.     struct BitMapHeader *bmhd;
  67.     UWORD colortable[128];
  68.  
  69.     if((argc != 4) || !strcmp(argv[1],"?")) {
  70.         printf("Format: %s filename <delaytime> <# of loops>\n",argv[0]);
  71.         exit(20);
  72.     }
  73.  
  74.     GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L);
  75.     IntuitionBase = OpenLibrary("intuition.library",0L);
  76.  
  77.     if(!(IFFBase = OpenLibrary(IFFNAME,IFFVERSION))) {
  78.         printf("Copy the iff.library to your LIBS: directory!\n");
  79.         exit(10);
  80.     }
  81.  
  82.     if(!(ifffile=OpenIFF(argv[1]))) Fail("Error opening file");
  83.     form=ifffile+3; /* Skip FORM....ANIM */
  84.  
  85.     if(ifffile[2] != ID_ANIM) Fail("Not an ANIM file");
  86.     if(!(bmhd=GetBMHD(form))) Fail("BitMapHeader not found");
  87.  
  88.     ns.Width     = bmhd->w;
  89.     ns.Height    = bmhd->h;
  90.     ns.Depth     = bmhd->nPlanes;
  91.     ns.ViewModes = GetViewModes(form);
  92.  
  93.     if(!(screen1 = OpenScreen(&ns))) Fail("Can't open screen 1!");
  94.     if(!(screen2 = OpenScreen(&ns))) Fail("Can't open screen 2!");
  95.     SetOverscan(screen1); SetOverscan(screen2);
  96.  
  97.     count = GetColorTab(form,colortable);
  98.     if(count>32L) count = 32L; /* Some HAM pictures have 64 colors ?! */
  99.     LoadRGB4(&(screen1->ViewPort),colortable,count);
  100.     LoadRGB4(&(screen2->ViewPort),colortable,count);
  101.  
  102.     /* Decode and display the first frame: */
  103.     if(!DecodePic(form,&screen1->BitMap)) Fail("Can't decode picture");
  104.     DecodePic(form,&screen2->BitMap);
  105.     ScreenToFront(screen2);
  106.     if((delay=atol(argv[2])) > 1) Delay(delay);
  107.  
  108.     /* Decode and display the second frame: copy and modify the first one */
  109.     form=FindChunk(ifffile+3,0L);        /* First FORM containing a DLTA */
  110.     if(!ModifyFrame(form,&screen1->BitMap)) Fail("Can't decode frame");
  111.     ScreenToFront(screen1);
  112.     if(delay>1) Delay(delay);
  113.  
  114.     loopform=FindChunk(form,0L);        /* FORM to start loop at */
  115.     for(i=0; i<atol(argv[3]); ++i)        /* Loop n times */
  116.     {
  117.         for(form=loopform; *form==ID_FORM; form=FindChunk(form,0L))
  118.         {
  119.             register struct Screen *dummy;
  120.             if(!ModifyFrame(form,&screen2->BitMap)) Fail("Can't decode frame");
  121.             dummy=screen1; screen1=screen2; screen2=dummy;    /* Flip screens */
  122.             ScreenToFront(screen1);
  123.             if(delay>1) Delay(delay);
  124.         }
  125.     }
  126.     Fail("done");     /* Close down the whole stuff */
  127. }
  128.  
  129.